package cn.bdqn.controller;

import cn.bdqn.domain.Admin;
import cn.bdqn.domain.Client;
import cn.bdqn.service.AdminClientService;
import cn.bdqn.utils.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 控制层
 * @author dkj
 */
@RestController
public class AdminClientController {

    @Autowired
    private AdminClientService adminClientService;

    /**
     * 添加管理员信息
     * @param admin
     * @return
     */
    @PostMapping("/admin/addInfo/")
    public Result addInfo(Admin admin){
        return adminClientService.addInfo(admin);
    }

    /**
     * 根据id查询管理员信息
     * @param id
     * @return
     */
    @GetMapping("/admin/queryInfoById/{id}")
    public Result queryInfoById(@PathVariable("id") Integer id){
        return adminClientService.queryInfoById(id);
    }

    /**
     * 根据手机号和密码查询管理员信息
     * @return
     */
    @PostMapping("/admin/login/")
    public Result queryInfoByPhoneAndPassword( String password,String phone){
        return adminClientService.queryInfoByPhoneAndPassword(password,phone);
    }
    /**
     * 根据手机号查询   用于判断手机号是否注册
     * @param phone
     * @return
     */
    @GetMapping("/admin/queryByPhoneIsExist/{phone}")
    public Result queryByPhoneIsExist(@PathVariable("phone") String phone){
        return adminClientService.queryByPhoneIsExist(phone);
    }
    /**
     * 查询全部并分页
     * @param pageNum
     * @param pageAmount
     * @return
     */
    @GetMapping("/admin/queryAllInfo/{pageNum}/{pageAmount}")
    public Result queryAllInfo(@PathVariable("pageNum") Integer pageNum,@PathVariable("pageAmount") Integer pageAmount){

        return adminClientService.queryAllInfo(pageNum,pageAmount);
    }
    /**
     * 根据管理员名和手机号模糊查询并分页
     * @param name
     * @param phone
     * @param pageNum
     * @param pageAmount
     * @return
     */
    @GetMapping("/admin/queryInfoByNameOrPhone/{name}/{phone}/{pageNum}/{pageAmount}")
    public Result queryInfoByNameOrPhone(@PathVariable("name") String name,
                                         @PathVariable("phone") String phone,
                                         @PathVariable("pageNum") Integer pageNum,
                                         @PathVariable("pageAmount") Integer pageAmount){
        return adminClientService.queryInfoByNameOrPhone(name, phone, pageNum, pageAmount);
    }
    /**
     * 修改管理员信息
     * @param admin
     */
    @PutMapping("/admin/alterInfo")
    public Result alterInfo(Admin admin){
        return adminClientService.alterInfo(admin);
    }

    /**
     * 逻辑删除管理员信息
     * @param id
     */
    @PutMapping("/admin/admin/alterInfo/{id}")
    public Result alterStateById(@PathVariable("id") Integer id){
        return adminClientService.alterStateById(id);
    }



    //***********************客户**********************

    /**
     * 添加客户信息
     * @param client
     */
    @PostMapping("/admin/client/addClientInfo/")
    public Result AddClientInfo(Client client){
        return adminClientService.AddClientInfo(client);
    }

    /**
     * 根据id查询用户信息
     *
     * @param id
     * @return
     */
    @GetMapping("/admin/client/queryInfoById/{id}")
    public Result queryById(@PathVariable("id")Integer id){
        return adminClientService.queryById(id);
    }
    /**
     * 根据手机号查询客户信息
     * @param phone
     * @return
     */
    @GetMapping("/admin/client/queryInfoByPhone/{phone}")
    public Result queryInfoByPhone(@PathVariable("phone") String phone){
        return adminClientService.queryInfoByPhone(phone);
    }

    /**
     * 根据手机号判断手机号是否已注册
     *
     * @param phone 电话
     * @return
     */
    @GetMapping("/admin/client/queryByPhoneIsExist/{phone}")
    public Result queryClientByPhoneIsExist(@PathVariable("phone")String phone){
        return adminClientService.queryClientByPhoneIsExist(phone);
    }

    /**
     * 查询全部并分页
     *
     * @param pageNum   当前页码
     * @param pageAmount    每页条数
     * @return
     */
    @GetMapping("/admin/client/queryAllInfo/{pageNum}/{pageAmount}")
    public Result queryAll(@PathVariable("pageNum")Integer pageNum, @PathVariable("pageAmount")Integer pageAmount){
        return adminClientService.queryAll(pageNum, pageAmount);
    }
    /**
     * 根据电话或姓名模糊查询信息并分页
     *
     * @param phone  客户电话
     * @param name   客户姓名
     * @param pageNum  当前页码
     * @param pageAmount  每页条数
     * @return
     */
    @GetMapping("/admin/client/queryInfoByPhoneAndName/{phone}/{name}/{pageNum}/{pageAmount}")
    public Result queryInfoByPhoneAndName(@PathVariable("phone")String phone,
                                          @PathVariable("name") String name,
                                          @PathVariable("pageNum") Integer pageNum,
                                          @PathVariable("pageAmount") Integer pageAmount){
        return adminClientService.queryInfoByPhoneAndName(phone, name, pageNum, pageAmount);
    }

    /**
     * 逻辑删除
     * @param id 主键id
     * @return
     */
    @PutMapping("/admin/client/alterStateById/{id}")
    public Result deleteStateById(@PathVariable("id")Integer id){
        return adminClientService.deleteStateById(id);
    }

    /**
     * 修改客户信息
     *
     * @param client
     */
    @PutMapping("/admin/client/alterInfo")
    public Result alterInfo(Client client){
        return adminClientService.alterInfo(client);
    }



}
